﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TramDangKiemQuangNam
{
    public partial class Login : Form
    {
        Dictionary<string, string> dangnhap = new Dictionary<string, string>();
        /*
        private const int WS_SYSMENU = 0x80000;
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.Style &= ~WS_SYSMENU;
                return cp;
            }
        }*/
        public Login()
        {
            dangnhap.Add("TrungtamDangkiemThuboQuangNam", "minhtamdkqn");
            dangnhap.Add("chitrung09t2@gmail.com", "chitrung09t2");
            dangnhap.Add("daihocbachkhoadanang@gmail.com", "bachkhoa");
            InitializeComponent();
            
        }
        protected override void OnShown(EventArgs e)
        {
            textBox2.Focus();
            this.textBox2.PasswordChar = '*';
            base.OnShown(e);
            //this.ControlBox = false;
        }
        
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (checkLogin(textBox1.Text,textBox2.Text)==true)
                //if ((textBox1.Text == "trungtamdangkiemthuyboquangnam@gmail.com") && (textBox2.Text == "congdoanmotc"))
            {
                this.Hide();
                //this.Close();
                Form1 frm1 = new Form1();
                frm1.ShowDialog();   
            }
            else
            {
                MessageBox.Show("Thông tin đăng nhập sai", "Thông báo", MessageBoxButtons.OK);
                this.textBox1.Text = "TrungtamDangkiemThuboQuangNam";
                this.textBox2.Text = "";
                this.textBox1.Focus();
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
            {
                button1.PerformClick();
            }
            //8/3/2014
            if (e.Modifiers == Keys.Control)
            {
                e.Handled = true;
                textBox2.SelectionLength = 0;
            }
            //
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            //8/3/2014
            if (e.Modifiers == Keys.Control)
            {
                e.Handled = true;
                textBox1.SelectionLength = 0;
            }
            //
        }
        private string TryGetLogin(string taikhoan)
        {
            if (dangnhap.ContainsKey(taikhoan))
                return dangnhap[taikhoan];
            else return "Access Denied";
        }
        private bool checkLogin(string taikhoan, string matkhau)
        {
            string kq;
            kq = TryGetLogin(taikhoan);
            if (kq == matkhau)
                return true;
            return false;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
      /*
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            if (e.CloseReason == CloseReason.WindowsShutDown) return;

            // Confirm user wants to close
            switch (MessageBox.Show(this, "Bạn có muốn thoát chương trình?", "Xác nhận!", MessageBoxButtons.YesNo))
            {
                /*
                case DialogResult.No:
                    e.Cancel = true;
                    break;
                default:
                    Application.Exit();
                    break;
                 ///
                case DialogResult.Yes:
                    Application.Exit();
                    break;
                default:
                    e.Cancel = true;
                    break;
            }
        }
         */
    }
}
